package cn.deschen.eshop.auth.config;

import cn.deschen.eshop.auth.filter.DynamicSecurityFilter;
import cn.deschen.eshop.auth.service.DynamicSecurityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.DefaultSecurityFilterChain;
import org.springframework.security.web.access.intercept.FilterSecurityInterceptor;
import org.springframework.stereotype.Component;

/**
 * @Author hanbin_chen
 * @Description 动态资源权限配置
 * @DateTime 2021/1/22 11:17
 * @Version V1.0.0
 */
@Component
public class DynamicSecurityConfig extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {

    @Autowired
    private DynamicSecurityService dynamicSecurityService;

    @Autowired
    private DynamicSecurityFilter dynamicSecurityFilter;

    @Override
    public void configure(HttpSecurity http) throws Exception {
        //有动态权限配置时添加动态权限校验过滤器
        if (dynamicSecurityService != null) {
            http
                    .addFilterBefore(dynamicSecurityFilter, FilterSecurityInterceptor.class);
        }
    }
}
